﻿@{
    Layout = null;
}
@model System.Collections.IEnumerable
<!DOCTYPE html>
<html>
@Html.Partial("LoadPanelPartial")
<head>
    <title></title>
    @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

        @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
    )
        @Html.DevExpress().GetScripts(
            new Script { ExtensionType = ExtensionType.ListBox }
    )

    <script>
        function nodeClick(s, e) {
            var names = e.node.name.split('|');
            if (names.length > 1) {
                parent.$("#contentframe").attr("src", names[0] + "?userID=" + names[1]);
            }
        }
        function nodeInit(s, e) {
            var hdFocusNodeName = $("#hdFocusNodeName").val();
            var node = null;
            if (hdFocusNodeName == "") {
                node = LeftTreeView.GetSelectedNode();
                if (node.name.indexOf('|') == -1 && node.nodes.length > 0) {
                    node = node.nodes[0];
                    while (node.name.indexOf('|') == -1 && node.nodes.length > 0) {
                        node = node.nodes[0];
                    }
                }
            }
            else {
                node = LeftTreeView.GetNodeByName(hdFocusNodeName);
            }
            if (node) {
                LeftTreeView.SetSelectedNode(node);
                var names = node.name.split('|');
                if (names.length > 1) {
                    parent.$("#contentframe").attr("src", names[0] + "?userID=" + names[1]);
                }
                else {
                    parent.$("#contentframe").attr("src", rootPath + "/Admin/User/AddGroup");
                }
            }
        }
        function refreshNodeName(nodeName) {
            var node = LeftTreeView.GetSelectedNode();
            node.SetText(nodeName);

        }
        /*刷新节点*/
        function refreshLevelNode(focusKey) {
            if (focusKey != "") {
                parent.$("#contentleft").attr("src", rootPath + "/Admin/User/UserTree?focusNodeName=" + focusKey);
            }
            else {
                parent.$("#contentleft").attr("src", rootPath + "/Admin/User/UserTree");
            }
        }
        /*删除节点*/
        function afterDeleteNode() {
            var node = LeftTreeView.GetSelectedNode();
            var nodeIndex = node.index;
            //            if (nodeIndex < LeftTreeView.GetNodeCount()) {
            //                if (nodeIndex == 0) {
            //                    node = LeftTreeView.GetNode(nodeIndex + 1)
            //                }
            //                else {
            //                    node = LeftTreeView.GetNode(nodeIndex - 1)
            //                }
            //            }


            if (node.parent.nodes.length > 1) {
                if (nodeIndex == 0) {
                    node = node.parent.nodes[nodeIndex + 1]
                } else {
                    node = node.parent.nodes[nodeIndex - 1]
                }
            } else {
                node = null;
            }



            if (node && node.name.indexOf('|') != -1) {
                parent.$("#contentleft").attr("src", rootPath + "/Admin/User/UserTree?focusNodeName=" + node.name);
            } else {
                parent.$("#contentleft").attr("src", rootPath + "/Admin/User/UserTree?focusNodeName=");
            }
        }
    </script>

</head>
<body>
    <div>
        @Html.DevExpress().TreeView(settings =>
{
    settings.Name = "LeftTreeView";
    settings.ShowTreeLines = true;
    settings.AllowSelectNode = true;
    settings.NameField = "Id";
    settings.TextField = "Name";
    settings.ImageUrlField = "ImageUrl";
    settings.ClientSideEvents.NodeClick = "function(s, e) { nodeClick(s,e) }";
    settings.ClientSideEvents.Init = "function(s, e) { nodeInit(s,e) }";    
    settings.PreRender = (source, e) =>
    {
        ASPxTreeView treeView = (ASPxTreeView)source;
       
        if (treeView.Nodes.Count>0)
        {
            treeView.SelectedNode = treeView.Nodes[0];
            if (treeView.Nodes[0].Nodes.Count > 0)
            {
                treeView.ExpandToNode(treeView.Nodes[0].Nodes[0]);
            }
        }
    };

}).Bind(Model).GetHtml()
    </div>
    <!--树形节点焦点值 -->
    @Html.Hidden("hdFocusNodeName", ViewData["focusNodeName"])

    <script type="text/javascript" language="javascript">
        lp.Hide();
    </script>

</body>
</html>
